<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML文本提取器</title>
    <script src="jquery-3.6.0.min.js"></script>
    <style>
        body {
            width: 500px;
            min-height: 400px;
            padding: 15px;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fa;
        }
        .container {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .header {
            text-align: center;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 1px solid #ddd;
        }
        .header h2 {
            margin: 0;
            color: #2c3e50;
        }
        .input-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: 600;
            color: #2c3e50;
        }
        textarea, input[type="text"] {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            box-sizing: border-box;
        }
        textarea {
            min-height: 120px;
            resize: vertical;
            font-family: monospace;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 10px 15px;
            font-size: 14px;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 5px;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #2980b9;
        }
        button.secondary {
            background-color: #95a5a6;
        }
        button.secondary:hover {
            background-color: #7f8c8d;
        }
        .button-group {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
        }
        .result-area {
            margin-top: 15px;
        }
        .error {
            color: #e74c3c;
            padding: 8px;
            background-color: #fadbd8;
            border-radius: 4px;
            margin-top: 10px;
            display: none;
        }
        .success {
            color: #27ae60;
            padding: 8px;
            background-color: #d5f4e6;
            border-radius: 4px;
            margin-top: 10px;
            display: none;
        }
        .page-info {
            background-color: #e8f4f8;
            padding: 8px;
            border-radius: 4px;
            margin-bottom: 10px;
            font-size: 12px;
        }
        .page-info div {
            margin-bottom: 5px;
        }
        .page-info .url {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .help-text {
            font-size: 12px;
            color: #666;
            margin-top: 5px;
            font-style: italic;
        }
        .toggle-container {
            display: flex;
            justify-content: center;
            margin-bottom: 15px;
        }
        .toggle-label {
            display: flex;
            align-items: center;
            gap: 10px;
            cursor: pointer;
            font-weight: 600;
            color: #2c3e50;
        }
        .toggle-switch {
            display: none;
        }
        .toggle-slider {
            position: relative;
            width: 50px;
            height: 24px;
            background-color: #ccc;
            border-radius: 24px;
            transition: background-color 0.3s;
        }
        .toggle-slider:before {
            content: '';
            position: absolute;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: white;
            top: 2px;
            left: 2px;
            transition: transform 0.3s;
        }
        .toggle-switch:checked + .toggle-slider {
            background-color: #4CAF50;
        }
        .toggle-switch:checked + .toggle-slider:before {
            transform: translateX(26px);
        }
        
        /* 配置管理模态框样式 */
        .modal {
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .modal-content {
            background-color: white;
            border-radius: 8px;
            width: 90%;
            max-width: 800px;
            max-height: 90vh;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        
        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 20px;
            border-bottom: 1px solid #ddd;
            background: #f8f9fa;
        }
        
        .modal-header h3 {
            margin: 0;
            color: #2c3e50;
        }
        
        .close {
            font-size: 24px;
            font-weight: bold;
            cursor: pointer;
            color: #aaa;
        }
        
        .close:hover {
            color: #000;
        }
        
        .modal-body {
            padding: 20px;
            max-height: 70vh;
            overflow-y: auto;
        }
        
        .config-tabs {
            display: flex;
            border-bottom: 1px solid #ddd;
            margin-bottom: 20px;
        }
        
        .tab-btn {
            background: none;
            border: none;
            padding: 10px 20px;
            cursor: pointer;
            border-bottom: 2px solid transparent;
            color: #666;
        }
        
        .tab-btn.active {
            color: #3498db;
            border-bottom-color: #3498db;
        }
        
        .tab-content {
            display: none;
        }
        
        .tab-content.active {
            display: block;
        }
        
        .search-box {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
        }
        
        .search-box input {
            flex: 1;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        
        .config-list {
            max-height: 300px;
            overflow-y: auto;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        
        .config-item {
            padding: 15px;
            border-bottom: 1px solid #f0f0f0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .config-item:last-child {
            border-bottom: none;
        }
        
        .config-info {
            flex: 1;
        }
        
        .config-url {
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 5px;
        }
        
        .config-selector {
            color: #666;
            font-size: 14px;
            margin-bottom: 3px;
        }
        
        .config-attribute {
            color: #999;
            font-size: 12px;
        }
        
        .config-actions {
            display: flex;
            gap: 5px;
        }
        
        .config-actions button {
            padding: 5px 10px;
            font-size: 12px;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        
        .edit-btn {
            background-color: #f39c12;
            color: white;
        }
        
        .delete-btn {
            background-color: #e74c3c;
            color: white;
        }
        
        .form-group {
            margin-bottom: 15px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: 600;
            color: #2c3e50;
        }
        
        .form-group input[type="text"] {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        
        .import-export-section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        
        .import-export-section h4 {
            margin: 0 0 10px 0;
            color: #2c3e50;
        }
        
        .import-export-section p {
            margin: 0 0 15px 0;
            color: #666;
        }
        
        /* 确认对话框样式 */
        .confirm-dialog-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            z-index: 2000;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .confirm-dialog {
            background: white;
            border-radius: 8px;
            padding: 20px;
            min-width: 300px;
            max-width: 400px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        
        .confirm-title {
            font-size: 18px;
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 10px;
        }
        
        .confirm-message {
            color: #666;
            margin-bottom: 20px;
            line-height: 1.5;
        }
        
        .confirm-buttons {
            display: flex;
            gap: 10px;
            justify-content: flex-end;
        }
        
        .confirm-btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s;
        }
        
        .confirm-yes {
            background-color: #e74c3c;
            color: white;
        }
        
        .confirm-yes:hover {
            background-color: #c0392b;
        }
        
        .confirm-no {
            background-color: #95a5a6;
            color: white;
        }
        
        .confirm-no:hover {
            background-color: #7f8c8d;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h2>HTML文本提取器</h2>
            <div class="toggle-container">
                <label class="toggle-label">
                    <span>激活/禁用</span>
                    <input type="checkbox" id="extension-toggle" class="toggle-switch">
                    <span class="toggle-slider"></span>
                </label>
            </div>
            <div class="page-info">
                <div class="url" id="page-url">当前页面: 未获取</div>
                <div class="title" id="page-title">标题: 未获取</div>
            </div>
        </div>
        
        <div class="input-group">
            <label for="selector-input">jQuery选择器（多个用 | 分隔）：</label>
            <div style="position: relative;">
                <input type="text" id="selector-input" class="selector-input" placeholder="例如：p, .classname, #id">
                <div id="selector-history" style="
                    position: absolute;
                    top: 100%;
                    left: 0;
                    right: 0;
                    background: white;
                    border: 1px solid #ddd;
                    border-top: none;
                    border-radius: 0 0 4px 4px;
                    max-height: 200px;
                    overflow-y: auto;
                    z-index: 1000;
                    display: none;
                    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
                "></div>
            </div>
        </div>
        
        <div class="input-group">
            <label for="attribute-input">属性名（可选，多个用 | 分隔）：</label>
            <input type="text" id="attribute-input" class="attribute-input" placeholder="例如：src, href, title, data-id">
            <div class="help-text">留空则提取文本内容，填写属性名则提取属性值</div>
        </div>
        
        <div class="input-group">
            <label>
                <input type="checkbox" id="extract-both" checked> 同时提取属性和文本
            </label>
            <div class="help-text">勾选后，每个元素会同时提取属性值和文本内容</div>
        </div>
        
        <div class="button-group">
            <button id="get-html-btn">获取当前页面HTML</button>
            <button id="load-examples-btn" class="secondary">加载示例</button>
            <button id="extract-btn">提取文本</button>
        </div>
        
        <div class="button-group">
            <button id="config-manage-btn" class="secondary">配置管理</button>
            <button id="auto-fill-btn" class="secondary">自动填充</button>
        </div>
        
        <div class="input-group">
            <label for="html-input">HTML源代码：</label>
            <textarea id="html-input" placeholder="点击上方按钮获取当前页面HTML..."></textarea>
        </div>
        
        <div class="input-group">
            <label for="result">提取结果：</label>
            <textarea id="result" readonly placeholder="提取结果将显示在这里..."></textarea>
        </div>
        
        <div id="error-message" class="error"></div>
        <div id="success-message" class="success"></div>
    </div>

    <!-- 配置管理模态框 -->
    <div id="config-modal" class="modal" style="display: none;">
        <div class="modal-content">
            <div class="modal-header">
                <h3>配置管理</h3>
                <span class="close">&times;</span>
            </div>
            <div class="modal-body">
                <div class="config-tabs">
                    <button class="tab-btn active" data-tab="list">配置列表</button>
                    <button class="tab-btn" data-tab="add">添加配置</button>
                    <button class="tab-btn" data-tab="import-export">导入/导出</button>
                </div>
                
                <!-- 配置列表标签页 -->
                <div id="tab-list" class="tab-content active">
                    <div class="search-box">
                        <input type="text" id="config-search" placeholder="搜索URL或选择器...">
                        <button id="search-config-btn">搜索</button>
                    </div>
                    <div id="config-list" class="config-list"></div>
                </div>
                
                <!-- 添加配置标签页 -->
                <div id="tab-add" class="tab-content">
                    <div class="form-group">
                        <label for="config-url">网页地址：</label>
                        <input type="text" id="config-url" placeholder="例如：https://example.com/page">
                    </div>
                    <div class="form-group">
                        <label for="config-selector">jQuery选择器：</label>
                        <input type="text" id="config-selector" placeholder="例如：p, .classname, #id">
                    </div>
                    <div class="form-group">
                        <label for="config-attribute">属性名：</label>
                        <input type="text" id="config-attribute" placeholder="例如：src, href, title">
                    </div>
                    <div class="form-group">
                        <label>
                            <input type="checkbox" id="config-extract-both"> 同时提取属性和文本
                        </label>
                    </div>
                    <div class="form-group">
                        <button id="save-config-btn">保存配置</button>
                        <button id="clear-config-form-btn" class="secondary">清空表单</button>
                    </div>
                </div>
                
                <!-- 导入/导出标签页 -->
                <div id="tab-import-export" class="tab-content">
                    <div class="import-export-section">
                        <h4>导出配置</h4>
                        <p>将当前所有配置导出为Excel文件</p>
                        <button id="export-config-btn">导出Excel</button>
                    </div>
                    <div class="import-export-section">
                        <h4>导入配置</h4>
                        <p>从Excel文件导入配置（将覆盖现有配置）</p>
                        <input type="file" id="import-config-file" accept=".xlsx,.xls,.csv">
                        <button id="import-config-btn">导入配置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="popup.js"></script>
</body>
</html>